home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / communicator / pref / pref-scripts.js < prev    next >
Encoding:
Text File  |  2002-04-12  |  8.9 KB  |  196 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla.org Code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Doron Rosenberg.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Jonas J°rgensen <jonasj@jonasj.dk>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const pref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
  39.  
  40. // need it globally, but can only set it in startup()
  41. var data;
  42.  
  43. function changeDisabledState(state){
  44.   //Set the states of the groupbox children state based on the "javascript enabled" checkbox value
  45.   document.getElementById("allowScripts").disabled = state;
  46.   document.getElementById("allowTargetNew").disabled = state;
  47.   document.getElementById("allowWindowMoveResize").disabled = state;
  48.   document.getElementById("allowWindowOpen").disabled = state;
  49.   document.getElementById("allowImageSrcChange").disabled = state;
  50.   document.getElementById("allowDocumentCookieSet").disabled = state;
  51.   document.getElementById("allowDocumentCookieGet").disabled = state;
  52.   document.getElementById("allowWindowStatusChange").disabled = state;
  53.   document.getElementById("allowWindowFlip").disabled = state;
  54. }
  55.  
  56. function javascriptEnabledChange(){
  57.   // if javascriptAllowMailNews is overlayed (mailnews is installed), then if javascriptAllowMailnews 
  58.   // and javascriptAllowNavigator are unchecked, we disable the tree items. 
  59.   // If javascriptAllowMailNews is not available, we only take javascriptAllowNavigator in consideration
  60.  
  61.   if (document.getElementById('javascriptAllowMailNews')){
  62.     if (!document.getElementById('javascriptAllowNavigator').checked && !document.getElementById('javascriptAllowMailNews').checked)
  63.       changeDisabledState(true);
  64.     else changeDisabledState(false);
  65.   } else {
  66.     changeDisabledState(!document.getElementById('javascriptAllowNavigator').checked);
  67.   }
  68. }
  69.  
  70. function getPrefValueForCheckbox(prefName){
  71.   var prefValue = false;
  72.  
  73.   try {
  74.     prefValue = pref.GetBoolPref(prefName);
  75.   }
  76.   catch(e) {}
  77.  
  78.   // the prefs are stored in terms of disabling,
  79.   // but we want our value in terms of enabling.
  80.   // so let's invert the prefValue.
  81.   return !prefValue;
  82. }
  83.  
  84. function Startup(){
  85.  
  86.   data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
  87.  
  88.   //If scriptData does not exist, then it is the first time the panel was shown and we default to false 
  89.   if (!("scriptData" in data)){
  90.     var changedList = ["allowWindowOpenChanged", "allowTargetNewChanged",
  91.                        "allowWindowMoveResizeChanged", "allowWindowStatusChangeChanged",
  92.                        "allowWindowFlipChanged", "allowDocumentCookieSetChanged",
  93.                        "allowDocumentCookieGetChanged", "allowImageSrcChangeChanged"];
  94.     data.scriptData = [];
  95.     for(var run = 0; run < changedList.length; run++ ){
  96.       data.scriptData[ changedList[run] ] = [];
  97.       data.scriptData[ changedList[run] ].value = false;
  98.     }
  99.  
  100.     document.getElementById("allowWindowOpen").checked = getPrefValueForCheckbox("dom.disable_open_during_load");
  101.     document.getElementById("allowTargetNew").checked = getPrefValueForCheckbox("browser.block.target_new_window");
  102.     document.getElementById("allowWindowMoveResize").checked =  getPrefValueForCheckbox("dom.disable_window_move_resize");
  103.     document.getElementById("allowWindowFlip").checked = getPrefValueForCheckbox("dom.disable_window_flip");
  104.     document.getElementById("allowWindowStatusChange").checked = getPrefValueForCheckbox("dom.disable_window_status_change");
  105.     document.getElementById("allowImageSrcChange").checked = getPrefValueForCheckbox("dom.disable_image_src_set");
  106.     document.getElementById("allowDocumentCookieGet").checked = getPrefValueForCheckbox("dom.disable_cookie_get");
  107.     document.getElementById("allowDocumentCookieSet").checked = getPrefValueForCheckbox("dom.disable_cookie_set");
  108.  
  109.   } else { //not first time it was loaded, get default values from data 
  110.  
  111.     document.getElementById("allowWindowOpen").checked = data["allowWindowOpen"].checked;
  112.     document.getElementById("allowTargetNew").checked = data["allowTargetNew"].checked;
  113.     document.getElementById("allowWindowMoveResize").checked = data["allowWindowMoveResize"].checked;
  114.     document.getElementById("allowWindowFlip").checked = data["allowWindowFlip"].checked;
  115.     document.getElementById("allowWindowStatusChange").checked = data["allowWindowStatusChange"].checked;
  116.     document.getElementById("allowImageSrcChange").checked = data["allowImageSrcChange"].checked;
  117.     document.getElementById("allowDocumentCookieSet").checked = data["allowDocumentCookieSet"].checked;
  118.     document.getElementById("allowDocumentCookieGet").checked = data["allowDocumentCookieGet"].checked;
  119.     document.getElementById("javascriptAllowNavigator").checked = data["javascriptAllowNavigator"].checked;
  120.  
  121.     if (document.getElementById("javascriptAllowMailnews")) {
  122.       document.getElementById("javascriptAllowMailNews").checked = data["javascriptAllowMailNews"].checked;
  123.     }
  124.   }
  125.  
  126.   javascriptEnabledChange();
  127.  
  128.   document.getElementById("AllowList").addEventListener("CheckboxStateChange", onCheckboxCheck, false);
  129.  
  130.   parent.hPrefWindow.registerOKCallbackFunc(doOnOk);
  131. }
  132.  
  133. function doOnOk(){
  134.  
  135.   //If a user makes a change to this panel, goes to another panel, and returns to this panel to 
  136.   //make another change, then we cannot use data[elementName].  This is because data[elementName] 
  137.   //contains the original xul change and we would loose the new change. Thus we track all changes
  138.   //by using getElementById.
  139.  
  140.   //The nested functions are needed because doOnOk cannot access anything outside of its scope
  141.   //when it is called 
  142.   function getCheckboxValue(name){
  143.     if ("onCheckboxCheck" in window)
  144.       return document.getElementById(name).checked;
  145.  
  146.     return data[name].checked;
  147.   }
  148.  
  149.   var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
  150.  
  151.   if (data.scriptData["allowWindowOpenChanged"].value){
  152.     parent.hPrefWindow.setPref("bool", "dom.disable_open_during_load",
  153.       !getCheckboxValue('allowWindowOpen'));
  154.   }
  155.  
  156.   if (data.scriptData["allowTargetNewChanged"].value){
  157.     parent.hPrefWindow.setPref("bool", "browser.block.target_new_window",
  158.       !getCheckboxValue('allowTargetNew'));
  159.   }
  160.  
  161.   if (data.scriptData["allowWindowMoveResizeChanged"].value){
  162.     parent.hPrefWindow.setPref("bool", "dom.disable_window_move_resize",
  163.       !getCheckboxValue('allowWindowMoveResize'));
  164.   }
  165.  
  166.   if (data.scriptData["allowWindowStatusChangeChanged"].value){
  167.     parent.hPrefWindow.setPref("bool", "dom.disable_window_status_change",
  168.       !getCheckboxValue("allowWindowStatusChange"));
  169.   }
  170.  
  171.   if (data.scriptData["allowWindowFlipChanged"].value){
  172.     parent.hPrefWindow.setPref("bool", "dom.disable_window_flip",
  173.       !getCheckboxValue("allowWindowFlip"));
  174.   }
  175.  
  176.   if (data.scriptData["allowDocumentCookieSetChanged"].value){
  177.     parent.hPrefWindow.setPref("bool", "dom.disable_cookie_set",
  178.       !getCheckboxValue("allowDocumentCookieSet"));
  179.   }
  180.  
  181.   if (data.scriptData["allowDocumentCookieGetChanged"].value){
  182.     parent.hPrefWindow.setPref("bool", "dom.disable_cookie_get",
  183.       !getCheckboxValue("allowDocumentCookieGet"));
  184.   } 
  185.  
  186.   if (data.scriptData["allowImageSrcChangeChanged"].value){
  187.     parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
  188.       !getCheckboxValue("allowImageSrcChange"));
  189.   }
  190. }
  191.  
  192. function onCheckboxCheck(event)
  193. {
  194.   data.scriptData[event.target.id+"Changed"].value = !data.scriptData[event.target.id+"Changed"].value;
  195. }
  196.